package com.yhyvr.api.controller.store.goods;/**
 * Created by zhangqin on 2017/6/28.
 */

import com.lz.kit.PropKit;
import com.lz.tool.ReadUrlTool;
import com.yhyvr.api.handle.ApiData;
import com.yhyvr.api.service.store.ApiGoodsService;
import com.yhyvr.api.tool.ViewFactory;
import com.yhyvr.pojo.req.api.ApiReqBody;
import com.yhyvr.pojo.req.api.ApiReqData;
import com.yhyvr.pojo.req.api.goods.ApiGoodsDetailReq;
import com.yhyvr.pojo.req.api.goods.ApiGoodsListReq;
import com.yhyvr.pojo.resp.api.ApiRespData;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.yhyvr.pojo.req.api.goods.ApiGoodsBannerReq;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 商品信息
 *
 * @author
 * @create 2017-06-28 11:28
 **/
@Controller
public class ApiGoodsController {
    @Resource
    private ApiGoodsService apiGoodsService;
    /**
     * 商品列表
     * @param apiReqBodyApiReqData
     * @return
     */
    @RequestMapping("/api/store/goods/list")
    public @ResponseBody
    ModelAndView goodsList (@ApiData(h5Visit=true,h5VisitToken = false) ApiReqData<ApiGoodsListReq> apiReqBodyApiReqData){
        return ViewFactory.buildApiJsonpView(apiGoodsService.goodsList(apiReqBodyApiReqData),apiReqBodyApiReqData.getCrossDomain());
    }
    /**
     * 商品列表热门
     * @param apiReqBodyApiReqData
     * @return
     */
    @RequestMapping("/api/store/goods/list/hot")
    public @ResponseBody
    ModelAndView goodsHotList (@ApiData(h5Visit=true,h5VisitToken = false) ApiReqData<ApiGoodsListReq> apiReqBodyApiReqData){
        return ViewFactory.buildApiJsonpView(apiGoodsService.hotList(apiReqBodyApiReqData),apiReqBodyApiReqData.getCrossDomain());
    }
    /**
     * 商品介绍
     * @param goodsId
     * @param apiReqBodyApiReqData
     * @return
     */
    @RequestMapping("/api/store/goods/detail/{goodsId}")
    public @ResponseBody
    ModelAndView goodsDetail (@PathVariable String goodsId, @ApiData(h5Visit=true,h5VisitToken = false) ApiReqData<ApiReqBody> apiReqBodyApiReqData){
        String serverUrl = PropKit.use("three-app.properties").get("sys.serverUrl");
        String detail = ReadUrlTool.readUrl(serverUrl+"/file/goods/detail/"+goodsId+".txt?"+new Date().getTime());
        return ViewFactory.buildApiJsonpView(ApiRespData.buildSucc(detail),apiReqBodyApiReqData.getCrossDomain());
    }

    /**
     * 商品信息
     * @param apiGoodsDetailReq
     * @return
     */
    @RequestMapping("/api/store/goods/info")
    public @ResponseBody
    ModelAndView goodsInfo (@ApiData(h5Visit=true,h5VisitToken = false) ApiReqData<ApiGoodsDetailReq> apiGoodsDetailReq){
        return ViewFactory.buildApiJsonpView(apiGoodsService.goodsInfo(apiGoodsDetailReq),apiGoodsDetailReq.getCrossDomain());
    }


    /**
     * 商品信息页面
     * @return
     */
    @RequestMapping("/api/store/page/goods/detail/{goodsId}")
    public String  goodsInfoProxy (ModelMap modelMap, @PathVariable String goodsId){
        modelMap.put("goodsId",goodsId);
        modelMap.put("goodsSallType",2);
        return "store/goods/detail";
    }

    /**
     * 试吃商品信息页面
     * @return
     */
    @RequestMapping("/api/store/page/goods/taste/detail/{goodsId}")
    public String  goodsInfoTaste (ModelMap modelMap, @PathVariable String goodsId){
        modelMap.put("goodsId",goodsId);
        modelMap.put("goodsSallType",5);
        return "store/goods/tasteDetail";
    }



    @RequestMapping("/api/store/goods/banner/list")
    public @ResponseBody
    ModelAndView goodsBannerList(@ApiData(h5Visit=true,h5VisitToken = false) ApiReqData<ApiGoodsBannerReq> apiReqData){

        return ViewFactory.buildApiJsonpView(apiGoodsService.list(apiReqData),apiReqData.getCrossDomain());
    }
}
